package com.example.demo.mapper;
import com.example.demo.pojo.RoleEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleMapper {

    // 分页查询角色列表
   @Select("SELECT * FROM roles")
    List<RoleEntity> getRolePage();

    // 查询角色总数
    @Select("SELECT COUNT(*) FROM roles")
    int getRoleCount();

    // 查询所有角色列表
    @Select("SELECT * FROM roles")
    List<RoleEntity> getAllRoles();

    // 添加角色
    @Insert("INSERT INTO roles (name, type, status, create_time, update_time) " +
            "VALUES (#{name}, #{type}, '1', NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int addRole(RoleEntity role);

    // 更新角色
    @Update("UPDATE roles SET status = #{status}, update_time = NOW() WHERE name = #{name}")
    int updateRole(RoleEntity role);

    @Update("UPDATE roles SET type = #{type}, name = #{name} ,update_time = NOW() WHERE name = #{name}")
    void updateRoleMnue(RoleEntity role);

    // 删除角色
    @Delete("DELETE FROM roles WHERE name = #{name}")
    int deleteRole(@Param("name") String name);

    // 查询单个角色
    @Select("SELECT * FROM roles WHERE name = #{name}")
    RoleEntity getRoleById(@Param("id") Long id);
}
